public class myPageController {

private Account acc = new Account();

private List<Account> accs;

private string selectedAccount;


public Account getAccount()

{

return acc;

}

public void setAccount(Account a)

{

acc = a;

}


public List<Account> getAccounts()

{

return accs;

}


public string getSelectedAccount()

{

return selectedAccount;

}

public void setSelectedAccount(string value)

{

selectedAccount = value;

}


public PageReference ViewAccounts()

{

if (acc.Type == null)

{

//view a message because validation has failed.

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Validation Failed: Select an item fron the dropdown list.'));

return null;

}


string AccountType = acc.Type;

accs = [Select id, name, type from Account where type= :AccountType limit 20];


if (accs == null || accs.size() == 0)

{

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'No data found to be shown.'));

}


return null;

}


public PageReference ShowSelected()

{

if (selectedAccount != null && selectedAccount != '')

{

for(Account a: accs)

{

if (a.Id == selectedAccount)

{

string Msg = a.Name + ' Account is selected.';

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,Msg ));

}

}

}


return null;

}

}